package org.csmzxy.class2334;

public class ShuiXianHuaShu {
    public static void main(String[] args){

        System.out.println(ShuiXianHuaShu(153));  // true
        System.out.println(ShuiXianHuaShu(370));  // true
        System.out.println(ShuiXianHuaShu(123));  // false
        System.out.println(ShuiXianHuaShu(9474)); // true
    }
    public static boolean ShuiXianHuaShu(int number){
        if (number < 0) {
            return false; // 负数不可能是水仙花数
        }
        int originalNumber = number;
        int sum = 0;
        int digits = String.valueOf(number).length();
        while (number > 0) {
            int digit = number % 10;
            sum += Math.pow(digit, digits);
            number /= 10;
        }
        return sum == originalNumber;
    }
}
